<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <!-- <label class="el-form-item-label">帐户编号</label> -->
        <!-- <el-input v-model.trim="query.accountId" clearable placeholder="帐户编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <label class="el-form-item-label">下单用户名</label>
        <el-input v-model.trim="query.customerName" clearable placeholder="下单用户名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">兑换时间</label>
        <date-range-picker
          v-model="query.exchangeTime"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="800px">
        <el-form ref="form" :model="form" :inline="true" :rules="rules" size="small" label-width="100px">
          <el-form-item label="帐户编号">
            <el-input v-model.trim="form.accountId" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="分成帐户名">
            <el-input v-model.trim="form.accountName" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="系统名称">
            <el-select v-model="form.systemId" filterable placeholder="请选择" style="width: 240px;" @change="cityGet(form.systemId)">
              <el-option
                v-for="item in system"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="城市编号">
            <el-select v-model="form.cityId" filterable placeholder="请选择" style="width: 240px;">
              <el-option
                v-for="item in city"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <!--          <el-form-item label="岗位名称">-->
          <!--            <el-select v-model="form.jobId" filterable placeholder="请选择" style="width: 240px;">-->
          <!--              <el-option-->
          <!--                v-for="item in job"-->
          <!--                :key="item.id"-->
          <!--                :label="item.name"-->
          <!--                :value="item.id"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <el-form-item label="当前分润比例">
            <el-input v-model="form.percent" type="number" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="获得积分点数">
            <el-input v-model="form.gainIntegral" type="number" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="下单用户名">
            <el-input v-model.trim="form.customerName" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="用户消费类型">
            <el-select v-model="form.consumeType" filterable placeholder="请选择" style="width: 240px;">
              <el-option
                v-for="item in dict.integral_detail_consume_type"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="用户消费点数">
            <el-input v-model="form.consumeAmount" type="number" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="兑换状态">
            <el-select v-model="form.exchangeStatus" filterable placeholder="请选择" style="width: 240px;">
              <el-option
                v-for="item in dict.integral_detail_exchange_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="兑换批号">
            <el-input v-model.trim="form.exchangeCard" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createTime" type="datetime" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="兑换时间">
            <el-date-picker v-model="form.exchangeTime" type="datetime" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model.trim="form.remark" style="width: 240px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="false" prop="id" label="编号" />
        <!-- <el-table-column prop="accountId" label="帐户编号" align="center" /> -->
        <el-table-column prop="accountName" label="用户名" align="center" />
        <!-- <el-table-column v-if="false" prop="systemId" label="systemId" align="center" /> -->
        <!-- <el-table-column prop="systemId" label="系统名称" align="center" /> -->
        <!-- <el-table-column v-if="false" prop="cityId" label="城市编号" align="center" /> -->
        <el-table-column prop="cityName" label="部门" align="center" />
        <!--        <el-table-column v-if="false" prop="jobId" label="岗位编号" align="center" />-->
        <!--        <el-table-column prop="jobName" label="岗位名称" align="center" />-->
        <el-table-column label="当前分润比例" align="center">
        <template slot-scope="scope">
          {{ (scope.row.percent/100).toFixed(2) }}
        </template>
        </el-table-column>
        <el-table-column label="获得积分点数" align="center">
          <template slot-scope="scope">
            {{ (scope.row.gainIntegral/100).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column prop="customerName" label="下单用户名" align="center" />
        <el-table-column prop="consumeType" label="消费类型" align="center">
          <template slot-scope="scope">
            {{ dict.label.integral_detail_consume_type[scope.row.consumeType] }}
          </template>
        </el-table-column>
        <el-table-column prop="consumeAmount" label="用户消费点数" align="center">
          <template slot-scope="scope">
            {{ scope.row.consumeAmount /100 }}
          </template>
        </el-table-column>
        <el-table-column prop="exchangeStatus" label="兑换状态" align="center">
          <template slot-scope="scope">
            {{ dict.label.integral_exchange_exchange_status[scope.row.exchangeStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="exchangeCard" label="兑换批号" align="center" />
        <el-table-column prop="createTime" label="创建时间" align="center">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="exchangeTime" label="兑换时间" align="center">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.exchangeTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" align="center" />

        <!-- <el-table-column v-permission="['admin','integralDetail:edit','integralDetail:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudIntegralDetail from '@/api/integral/integralDetail'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import crudDept from '@/api/system/dept'
import crudJob from '@/api/system/job'
import DateRangePicker from '@/components/DateRangePicker'

const defaultForm = { id: null, accountId: null, accountName: null, cityId: null, cityName: null, jobId: null, jobName: null, percent: null, gainIntegral: null, customerName: null, consumeType: null, consumeAmount: null, exchangeStatus: null, exchangeCard: null, createTime: null, exchangeTime: null, remark: null, systemId: null, systemName: null }
export default {
  name: 'IntegralDetail',
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['integral_detail_consume_type', 'integral_detail_exchange_status', 'integral_exchange_exchange_status'],
  cruds() {
    return CRUD({ title: '积分明细', url: 'api/integralDetail', idField: 'id', sort: 'id,desc', crudMethod: { ...crudIntegralDetail },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: true,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'integralDetail:add'],
        edit: ['admin', 'integralDetail:edit'],
        del: ['admin', 'integralDetail:del']
      },
      rules: {
      },
      system: '',
      city: '',
      job: ''
    }
  },
  mounted() {
    this.systemGet()
    this.jobGet()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh](a, b) {
      a.query.accountId = this.$route.query.accountId
      return true
    },
    [CRUD.HOOK.afterToCU](crud, form) {
      form.consumeAmount = form.consumeAmount / 100
      form.exchangeStatus = form.exchangeStatus.toString()
      form.consumeType = form.consumeType.toString()
      form.systemId = form.systemId.toString()
      form.cityId = form.cityId.toString()
    },
    systemGet() {
      // 获取系统下拉框数据
      let pro = {}
      const that = this
      setTimeout(() => {
        crudDept.getDepts({ pidIsNull: true }).then(res => {
          pro = res
          that.system = res.content
        })
      }, 100)
    },
    cityGet(id) {
      let pro = {}
      const that = this
      setTimeout(() => {
        crudDept.getDeptsListPidIsNull({ pid: id }).then(res => {
          pro = res
          that.city = res.content
        })
      }, 100)
    },
    jobGet() {
      let pro = {}
      const that = this
      setTimeout(() => {
        crudJob.getAllJob().then(res => {
          pro = res
          that.job = res.content
        })
      }, 100)
    }
  }
}
</script>
<style scoped lang="scss">
  .head-container {
    /** 去除input输入框样式 */
    ::v-deep  input[type=number]::-webkit-inner-spin-button {
      -webkit-appearance: none;
    }
	::v-deep input[type="number"]{
	    -moz-appearance:textfield;
	}
  }
</style>
